%define _PARSE_ELF_MAC_EXTERN_OR_GLOBAL_ 1 

%include"../include/parse_elf.mac" 

[section .text]
;get ELF header information 
;input:
;	1.elf addr.Starting memory address of ELF file; 
;	2.info addr.Header information structure address. 
;output:
;	1.information store in structure elf_header. 

;Stack frame: 
;|elf addr	|(32 bits) 
;|info addr	|(32 bits)  

;|ip		| 
;|bp		| 
get_elf_header_info: 
	push bp 
	mov bp,sp ;stack frame pointer 
	push eax 
	push esi 
	push edi 
	
	;clear eax,esi 
	xor eax,eax 
	xor esi,esi 
	xor edi,edi 

	;get parameter 
	mov edi,dword[bp+4] 
	mov esi,dword[bp+8] 

	;get program entry  
	mov eax,dword[esi+E_ENTRY_FILE_OFF] 
	mov dword[edi+Elf32_Ehdr.e_entry],eax 

	;get progran header table file offset
	mov eax,dword[esi+E_PHOFF_FILE_OFF] 
	mov dword[edi+Elf32_Ehdr.e_phoff],eax 

	;get elf header size 
	mov eax,dword[esi+E_EHSIZE_FILE_OFF] 
	mov dword[edi+Elf32_Ehdr.e_ehsize],eax 

	;get program header entry size  
	mov eax,dword[esi+E_PHENTSIZE_FILE_OFF] 
	mov dword[edi+Elf32_Ehdr.e_phentsize],eax 

	;get progran header entry number 
	mov eax,dword[esi+E_PHNUM_FILE_OFF] 
	mov dword[edi+Elf32_Ehdr.e_phnum],eax 

	pop edi 
	pop esi 
	pop eax 
	pop bp 
	ret 
